//
//  aboutViewController.m
//  酒店直通车
//
//  Created by wangqiang on 15/1/21.
//  Copyright (c) 2015年 wangqiang. All rights reserved.
//

#import "aboutViewController.h"

@interface aboutViewController()
{
    UILabel * titleNameLabel;
    UILabel * visnLabel;
    UILabel * detailLabel;
    UILabel * copyRightLabel;
    UIButton * webBtn;
}

@end

@implementation aboutViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom
        [self prepareMainView];
    }
    return self;
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    visnLabel.text = [NSString stringWithFormat:@"%@ v%@",NSLocalizedString(@"about", nil),[[[NSBundle mainBundle]infoDictionary]objectForKey:@"CFBundleShortVersionString"]];//CFBundleVersion
    detailLabel.text = NSLocalizedString(@"shareDefualt", nil);
    [webBtn setTitle:NSLocalizedString(@"webSite", nil) forState:0];
    copyRightLabel.text = NSLocalizedString(@"copyRight", nil);
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    self.navigationItem.title = NSLocalizedString(@"mineAbout", nil);
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)prepareMainView
{
    float ScreenWidth = [UIScreen mainScreen].bounds.size.width;
    float x = ScreenWidth / 2.0 - 40;
    float y = 94;
    float width = 80;
    float height = width;
    
    UIImageView * iconView = [[UIImageView alloc]initWithFrame:CGRectMake(x, y, width, height)];
    iconView.image = [UIImage imageNamed:@"ic_QRMaster_ios_160"];
    iconView.layer.cornerRadius = 10;
    iconView.layer.masksToBounds  =YES;
    [self.view addSubview:iconView];
    
    
    x = 0 ;
    y += height + 20;
    width = ScreenWidth;
    height = 20;
    visnLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, y, width, height)];
    visnLabel.textColor = RGBA(211, 211, 211, 1);
    visnLabel.font = [UIFont systemFontOfSize:16.0];
    visnLabel.textAlignment = NSTextAlignmentCenter;
    visnLabel.text = [NSString stringWithFormat:@"%@ v%@",NSLocalizedString(@"about", nil),[[[NSBundle mainBundle]infoDictionary]objectForKey:@"CFBundleShortVersionString"]];
    [self.view addSubview:visnLabel];

    
    y = visnLabel.frame.origin.y + visnLabel.frame.size.height + 10;
    height = 20;
    width = ScreenWidth - x * 2;
    detailLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, y, width, height)];
    detailLabel.text = NSLocalizedString(@"shareDefualt", nil);
    detailLabel.numberOfLines = 0;
    detailLabel.font = [UIFont systemFontOfSize:18.0];
    detailLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:detailLabel];
    
    
    x = ScreenWidth / 2.0 - 50;
    y = [UIScreen mainScreen].bounds.size.height - 80-64;
    width = 100;
    height = 15;
    webBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    webBtn.frame = CGRectMake(x, y, width, height);
    [webBtn setTitle:NSLocalizedString(@"webSite", nil) forState:0];
    [webBtn setTitleColor:RGBA(0, 119, 181, 1) forState:0];
    webBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
    [webBtn addTarget:self action:@selector(UseWebView) forControlEvents:UIControlEventTouchUpInside];
    webBtn.titleLabel.font = [UIFont systemFontOfSize:14.0];
    [self.view addSubview:webBtn];
    
    
    x = 0;
    width = ScreenWidth;
    y += height + 10;
    height = 40;
    copyRightLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, y, width, height)];
    copyRightLabel.textAlignment = NSTextAlignmentCenter;
    copyRightLabel.text = NSLocalizedString(@"copyRight", nil);
    copyRightLabel.font = [UIFont systemFontOfSize:14.0];
    copyRightLabel.numberOfLines = 2;
    copyRightLabel.textColor = [UIColor blackColor];
    [self.view addSubview:copyRightLabel];

}

-(void)UseWebView
{
     float ScreenWidth = [UIScreen mainScreen].bounds.size.width;
    webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, [UIScreen mainScreen].bounds.size.height - 64)];
    
    webView.delegate = self;
    
    webView.scalesPageToFit = YES;
    
    [self.view addSubview:webView];
    
    activityIndicatorView = [[UIActivityIndicatorView alloc]
                             
                             initWithFrame : CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)] ;
    
    [activityIndicatorView setCenter: self.view.center] ;
    
    [activityIndicatorView setActivityIndicatorViewStyle: UIActivityIndicatorViewStyleGray] ;
    
    [self.view addSubview : activityIndicatorView] ;
    
    NSURL *url =[NSURL URLWithString:@"http://www.uclbrt.com"];
    
    NSURLRequest *request =[NSURLRequest requestWithURL:url];
    
    [webView loadRequest:request];
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = RGBA(237, 238, 241, 1);
}

- (void)webViewDidStartLoad:(UIWebView *)webView
{
    
    [activityIndicatorView startAnimating] ;
    
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    
    [activityIndicatorView stopAnimating];
    
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    
    UIAlertView *alterview = [[UIAlertView alloc] initWithTitle:@"" message:[error localizedDescription]  delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
    [alterview show];
}


@end
